package com.hub.controller;

import com.hub.dto.PageParam;
import com.hub.dto.auth.MenuParam;
import com.hub.entity.AuthMenu;
import com.hub.service.IAuthMenuService;
import com.hub.utils.ApiResultObject;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 菜单Controller
 *
 * @description:
 * @author hub
 * @create: 2020-05-16 11:03
 */
@RestController
@RequestMapping("/menu")
public class AuthMenuController {

    @Autowired
    private IAuthMenuService authMenuService;

    @RequiresPermissions("Menu")
    @ApiOperation("获取菜单树")
    @PostMapping("/tree")
    public ApiResultObject getList(){
        return authMenuService.getMenuTree();
    }

    @RequiresPermissions("Menu")
    @ApiOperation("获取菜单列表")
    @PostMapping("/list")
    public ApiResultObject getList(@RequestBody PageParam<AuthMenu> pageParam){
        return authMenuService.getList(pageParam);
    }

    @RequiresPermissions("Menu")
    @ApiOperation("获取菜单列表")
    @PostMapping("/create")
    public ApiResultObject create(@RequestBody MenuParam param){
        return authMenuService.createMenu(param);
    }

    @RequiresPermissions("Menu")
    @ApiOperation("修改菜单")
    @PutMapping("/{menuId}")
    public ApiResultObject update(@PathVariable @NotNull Long menuId, @RequestBody MenuParam param){
        return authMenuService.updateMenu(menuId, param);
    }

    @RequiresPermissions("Menu")
    @ApiOperation("删除菜单")
    @DeleteMapping("/{menuId}")
    public ApiResultObject delete(@PathVariable @NotNull Long menuId){
        return authMenuService.deleteMenu(menuId);
    }
}
